package array;

import java.util.HashSet;

public class RemoveDuplicates {
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,1,2,3,3};
        int len = solutionDiff(nums);
        System.out.println(len);
        for (int i = 0; i < len; i++) {
            System.out.print(nums[i] + "/");
        }
    }
    public static int solution(int[] nums) {
        int slow = 0;
        int fast = slow + 1;
        int count = 0;
        while (fast < nums.length) {
            if(fast >= nums.length) break;
            if(nums[fast] <= nums[slow]){
                fast++;
            }else {
                slow++;
                nums[slow] = nums[fast];
                count++;
            }
        }
        return count + 1;
    }
    public static int solutionDiff(int[] nums) {
        //0,0,1,1,1,1,1,2,2,3,3,4
        //0,0,1,1,1,1,2,3,
        int numLen = nums.length;
        int slow = 0;
        int fast = slow + 2;
        while (fast < numLen && slow < numLen) {
            if (nums[slow] != nums[fast]) {
                nums[slow + 2] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow + 2;
    }
}
